package com.ruoyi.notice.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.notice.enums.MessageTypeEnum;
import com.ruoyi.notice.enums.SendTypeEnum;
import com.ruoyi.notice.factory.HandleMsgFactory;
import com.ruoyi.notice.factory.SendMsgFactory;
import com.ruoyi.notice.model.result.HandleMsgResult;
import com.ruoyi.notice.model.result.SendMsgResult;
import com.ruoyi.notice.service.IHandleMessageService;
import com.ruoyi.notice.service.IMessageNoticeService;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=530ef541-d3fc-433d-b738-967036fccebb
 */

@Service
public class MessageNoticeServiceImpl implements IMessageNoticeService {

    @Override
    public void noticeMsgHandle(MessageTypeEnum messageTypeEnum, List<String> dataIdList, JSONObject extData){

        try {

            IHandleMessageService service = HandleMsgFactory.getService(messageTypeEnum.getValue());
            if (ObjectUtil.isEmpty(service)){
                return;
            }

            // 获取消息处理结果
            List<HandleMsgResult> handleMsgResultList = service.toHandleNoticeMessage(dataIdList, extData);

            for (HandleMsgResult handleMsgResult : handleMsgResultList) {
                SendMsgResult sendMsgResult = SendMsgFactory.getService(handleMsgResult.getSendTypeEnum().getValue()).toSendMessage(handleMsgResult);
            }

        }catch (Exception exception){
            HandleMsgResult handleMsgResult = new HandleMsgResult();
            handleMsgResult.setContent("发送信息异常：" + JSON.toJSONString(exception));
            SendMsgResult sendMsgResult = SendMsgFactory.getService(SendTypeEnum.WEIXIN_QIYE.getValue()).toSendMessage(handleMsgResult);
        }
    }


    public static void main(String[] args) {

        String content = "ZgJvhXScgpnl2e3PGzfpNnW9/ozlw69WjhH7WmjV2pziO+9kJxmeqeu6te6zWwmonNEJNkfrxX2qNf5x25OcgWV4bvhcQxAO8Y4XIsFmfDdhag8onlGiT4rmFQxGvJ2U7pJ/haQy/ykMGW/vlXdqlychcQonRJ4GMf1kQ89NXUIQTHJfkW3j/UBdd4vqY1+Y1zei4gdInv03ZvjjeC7XUf+V9H+aeqGFYablgQztEFCiJDvSOs4EwWSoor1ewWReCXLcUcslYeP83hDnqbKbrEaQIL8ta9IaMjjX1JnHSqVd+7iq+a3Y1blF6JObQBbieDhhUquxYPIBT/qNsDCDfOR2AxOYhy+ZF4AAnwVLS86b01gr89l03ndskNJrx0GSFtMkZen3gIUjA/ZdUhj/hbJCSuagGbjlET1yWRXs4sIW3uE+RCsJDaKNyhiNQzZcJ/5Ug/w5gneOadzUOFz/kg==";
//        String aesKey = "KKXJHT9H5HJP28RYUJN1Z6W20KL0Y8UE";
        String aesKey = "KKXJHT9H5HJP28RY";

        String info = "{\"age\":\"31\",\"baitiao\":\"bt001\",\"baodan\":\"in001\",\"car\":\"car001\",\"cityCode\":\"310000\",\"enterpriseOwner\":\"eo001\",\"gjj\":\"gjj002\",\"house\":\"hu001\",\"huabei\":\"hb001\",\"loamAmount\":\"1202\",\"mobileMd5\":\"e50246953500e5d6fb788d0f29cc6183\",\"orderNo\":\"c5e11fdc94d34f6d8f19c8a425951608\",\"sex\":\"2\",\"shebao\":\"si002\",\"xueli\":\"xl001\",\"yuqi\":\"yq001\",\"zhima\":\"zm001\"}";

        JSONObject jsonObject = JSON.parseObject(info);

        String encryptData = SecureUtil.aes(aesKey.getBytes(StandardCharsets.UTF_8)).encryptBase64(jsonObject.toJSONString());

        System.out.println(encryptData);
        String s = SecureUtil.aes(aesKey.getBytes(StandardCharsets.UTF_8)).decryptStr(content);

        System.out.println(s);


        /**
         * D7qBEgEFxqXwRG4wKanRgY8dYujTaiDGCUzmFSPCIh8qQ6mcBfmQPbUyo6H5mjQ+Wjisxx+G6VUrICjhuHFQfPlrqcaMdXwNGEmsWgNyfAdI/VBfLGZLc3L62Uz41X2lFkuj0Th+i8FpzSf2nwpxfCKe1AlDldQN8ovq1KXvgtU36Zfd+gCU3uXMwHLOwgFUTD7OJmLSULQBOsO7Di2qy0iYq5DT+sunPOVbFQVNE33bayH+DkuHoMM7+w21gzZH4TY+YhPnAZ3ZpMGPlMQURe6qg5ThMl+o0sg6ImW9Y2rDlOEnlQOua7eBKyEE+hQoCrjE7mANzWkeVKtYu/KG6LzKmWMVvkcb+BhJynS38uJ7V9axMe0dj3RJ54mLlOmXh/0453hSHberG9yWj3xkZeu2sv8sC4TJr0WnQlCLmY59KKMd4KRFSIbALiPbcSRlnLUVpNRXbAjHf6Rmp6mxMw==
         */

        /**
         * D7qBEgEFxqXwRG4wKanRgY8dYujTaiDGCUzmFSPCIh8qQ6mcBfmQPbUyo6H5mjQ+Wjisxx+G6VUrICjhuHFQfPlrqcaMdXwNGEmsWgNyfAdI/VBfLGZLc3L62Uz41X2lFkuj0Th+i8FpzSf2nwpxfCKe1AlDldQN8ovq1KXvgtU36Zfd+gCU3uXMwHLOwgFUTD7OJmLSULQBOsO7Di2qy0iYq5DT+sunPOVbFQVNE33bayH+DkuHoMM7+w21gzZH4TY+YhPnAZ3ZpMGPlMQURe6qg5ThMl+o0sg6ImW9Y2rDlOEnlQOua7eBKyEE+hQoCrjE7mANzWkeVKtYu/KG6LzKmWMVvkcb+BhJynS38uJ7V9axMe0dj3RJ54mLlOmXh/0453hSHberG9yWj3xkZeu2sv8sC4TJr0WnQlCLmY59KKMd4KRFSIbALiPbcSRlnLUVpNRXbAjHf6Rmp6mxMw==
         */

    }



}
